﻿@using Domain.Model
@model IEnumerable<SiteMap>

<div class="row" style="margin-bottom:20px;">
    <input type="text" id="serachSiteMapInput" class="form-control" placeholder="Serach Sitemaps" aria-label="Serach Sitemaps" aria-describedby="basic-addon1" value=@ViewBag.query>
</div>
<div class="row">
    <table class="table table-bordered">
        <thead>
            <tr>
                <th scope="col">ID</th>
                <th scope="col">Domain</th>
                <th scope="col"></th>
            </tr>
        </thead>
        <tbody>
            @foreach (var it in Model ?? Enumerable.Empty<SiteMap>())
            {
                <tr>
                    <th>@it.Name</th>
                    <td>@it.Domain</td>
                    <td>
                        <a class="btn btn-primary" asp-controller="Selector" asp-action="Detail" asp-route-siteMapId=@it.Id>Detail</a>
                        <a class="btn btn-danger" asp-controller="SiteMap" asp-action="Delete" asp-route-Id=@it.Id>Delete</a>
                    </td>
                </tr>
            }
        </tbody>
    </table>
</div>
@section Scripts {
    <script>
        $().ready(function(){
        //$('#serachSiteMapInput').bind('keypress',function(event){
        //    console.log(location.origin+"?"+$('#serachSiteMapInput').val());
        //    //location.href=location.origin+"?"+$('#serachSiteMapInput').val();
        //});
        $('#serachSiteMapInput').change(function(event){
            if($('#serachSiteMapInput').val()!==""){
                location.href=location.origin+"?query="+$('#serachSiteMapInput').val();
            }else{
                location.href=location.origin
            }
        });
    });
    </script>
}